package com.yft.controller.posinformation;

import com.yft.entity.base.Order;
import com.yft.entity.base.OrderSort;
import com.yft.entity.base.Pager;
import com.yft.entity.base.PagerImpl;
import com.yft.entity.posinformation.PosMachine;
import com.yft.service.pos_information.PosMachineService;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@Controller
public class PosMachineController {
	private static final String controllerPath = "/yft/posMachine/";
//	private String viewpath = "/admin/base/jsp/PosMachineManage/";
	private String jsonViewpath = "/admin/pos_information/jsp/json/";
	
	@Autowired(required = true)
	private PosMachineService posMachineService;

	private boolean checkNullBlank(Object[] array){
		if(array==null || array.length==0){
			return false;
		}
		for(int i=0;i<array.length;i++){
			if(array[i] != null && !"".equals(((String)array[i]).trim())){
				continue;
			}else{
				return false;
			}
		}
		return true;
	}
	@RequestMapping(controllerPath + "getPosMachineList.html")
	public String getAgentInfoListJson(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap) {
		PosMachine condition = new PosMachine();
		Pager pager = new PagerImpl();
		String name = StringUtils.trimToEmpty(request.getParameter("name"));
		String limit = request.getParameter("limit");
		if(name!=null && name.length()>0){

		}
		int pageSize = 7;
		if (limit != null && limit.length() > 0)
			pageSize = NumberUtils.toInt(limit) > 0 ? NumberUtils.toInt(limit) : pageSize;
		String start = request.getParameter("start");
		int page = 1;
		if (start != null && start.length() > 0)
			page = NumberUtils.toInt(start) / pageSize + 1;
		pager.setPageSize(pageSize);
		pager.setPage(page);
		Order order = new Order();
		order.addOrder("createTime", OrderSort.DESC);
		
		List<PosMachine> posMachineList =  posMachineService.getPosMachineList(condition, order, pager);

        modelMap.addAttribute("totalProperty",pager.getRecordCount());
        modelMap.addAttribute("posMachineList",posMachineList);
		
		return jsonViewpath + "pos_machine";
	}


}
